1. Technical Field
The present invention relates to a method and apparatus for processing data in a disk drive, and, in particular, to a method and apparatus for reading and writing data using a segmented sector buffer.
2. Description of the Background Art
Computers use hard disk drive (HDD) systems to store large amounts of data. HDD systems comprise a plurality of magnetic storage disks (hereinafter referred to as disks) and data is stored in a concentric pattern of tracks on each disk. A magnetic head (hereinafter referred to as head) reads and writes the data on the disk. The head is positioned over a desired track when reading or writing data on the disk.
Generally, HDD systems require a memory called a sector buffer to temporarily store data in the HDD system because the data transfer rate of the disk is not equal to the data transfer rate of a host computer (hereinafter referred to as host). For example, when the host sends a read instruction to the HDD system, the HDD system stores the data read from the disk in the sector buffer. After a specified amount of data is stored in the sector buffer, the HDD system transfers the data to the host.
When the host sends a write instruction to the HDD system, the HDD system stores the data sent from the host in the sector buffer. The HDD system performs a seek to the desired track and writes the data on the target sector.
Using a sector buffer as a read ahead buffer or as a memory for a write cache for reading and writing data is a well-known technique for increasing the data I/O rate of new high capacity HDD systems. In response to a read instruction, the HDD system reads data from a sector and transfers the data. It is likely that another read instruction will be issued for the sector immediately following the sector in the preceding read request. To quickly start data transfer for the next request, it is very effective to perform, a read ahead or look ahead operation. Sector data is read in response to a first read instruction. In a read ahead or look ahead operation, the sector data immediately following the requested sector is read before the host issues a corresponding read instruction. The read ahead buffer is a memory which stores the data from the sector immediately following the requested sector.
In response to a write instruction, the HDD system writes data sent from the host to a specified sector on the disk, and informs the host when the write is finished. If the host is informed when the data transfer is finished but before the data is written to disk, from the host's view, the processing time to complete a write instruction is reduced. In a write cache, data sent from the host is stored in the sector buffer, and the host is informed of the end of a write when the data transfer to the HDD system is finished and before the write is actually finished.
Such sector buffers have increasingly large capacity due to reduced costs of memories. Therefore, a technique called segmentation wherein a sector buffer is divided into a plurality of regions (hereinafter referred to as segments) is commonly used. Using a high capacity segmented sector buffer as memory for a read ahead buffer or a write cache allows data in a plurality of sectors to be read ahead into a plurality of segments and to be write-cached in a plurality of segments.
The use of a large capacity sector buffer divided into a plurality of segments in a read or write instruction is as follows:
In response to a read instruction, the HDD system first sets a segment retaining at least part of the sector data requested by the host as a segment in the sector buffer to be processed. If a plurality of segments are associated with the request, the HDD system must attempt to identify (1) a segment retaining the data in the leading sector, (2) a segment retaining the largest part of the requested sector data, and (3) a segment that can most efficiently process the number of sectors requested. If such a segment cannot be selected (no segment retains the requested sector data), the HDD system must then attempt to identify (4) a segment least recently used, (5) a segment retaining the minimum number of sectors, and (6) a segment that can most efficiently process the number of sectors requested. If the set segment retains a specified amount or more of data (that can be transferred to the host), the HDD system then starts data transfer and reads missing sector data from the disk. The HDD system informs the host when all the requested sector data is transferred.
Similarly, in response to a write instruction, the HDD system first sets a segment in the sector buffer to be processed. Since the HDD system must update the sector data requested by the host, it must invalidate the data retained in the segment. To efficiently perform invalidation, the HDD system must identify (1) a segment retaining a minimum amount of sector data other than those requested, (2) a segment least recently used, and (3) a segment that can most efficiently process the number of sectors requested. The HDD system starts transferring a specified amount of data (sent from the host) to the set segment, writes the data to the corresponding sector on the disk, and informs the host when all the requested sector data is transferred. The HDD system subsequently finishes processing by writing all the requested sector data to the corresponding sectors on the disk.
However, in conventional HDD systems, once a segment is set to be processed, the segment continues to be used until processing is complete and some sector data may be retained in a plurality of segments. Referring to FIG. 13a, if the host issues a read request for sectors S.sub.R1 and S.sub.R2 and part of the data is contained in segments SG.sub.x and SG.sub.y, the HDD system sets segment SG.sub.x, as the segment to be processed. Since segment SG.sub.x, retains the data preceding S.sub.RA, to transfer all the data, the HDD system starts transferring the sector data (indicated by arrow R.sub.1) and reads missing sector data (indicated by arrow R.sub.2). Referring to FIG. 13b, as a result, the data from sectors S.sub.RC to S.sub.RD is retained in both segments SG.sub.x and SG.sub.y.
Referring now to FIG. 13c, in response to a write instruction, since the HDD system must invalidate data retained in certain segments, the HDD system must check related segments and invalidate the data retained each of the identified segments. That is, since a request from the host involves sectors S.sub.R3 to S.sub.R4 but both segments SG.sub.x and SG.sub.y contain the data, the data in both segments must be invalidated.
Consequently, the sector buffer is not efficiently used because the same data may exist in a plurality of segments. The HDD system must also check for segments containing data to be updated to invalidate the data retained in each of the identified segments. This results in complex processing and increases the burden on the local CPU controlling the sector buffer.